package com.df.bpm.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import com.df.bpm.entity.BusinessInputs;
import com.df.bpm.service.impl.BusinessInputsServiceImpl;
import com.df.common.utils.CommonUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;


/**
 * 业务输入控制器
 */
@Slf4j
@Tag(name = "业务主体控制器")
@RequestMapping("/businessInputs")
@RequiredArgsConstructor
@RestController
@SaCheckLogin
public class BusinessInputsController {
    /**
     * 业务输入服务
     */
    public final BusinessInputsServiceImpl businessInputsServiceImpl;

    /**
     * 获取业务输入信息
     * @param temp 业务输入线索
     */
    @Operation(summary = "获取业务输入信息", description = "获取业务输入信息")
    @PostMapping("getList")
    @SaIgnore
    public ResponseEntity<List<BusinessInputs>> getList(@RequestBody BusinessInputs temp) {
        return ResponseEntity.ok(businessInputsServiceImpl.getList(temp));
    }

    /**
     * 更新（业务输入信息）
     * @param temp 业务输入信息
     */
    @Operation(summary = "更新（业务输入信息）", description = "更新（业务输入信息）")
    @PostMapping("update")
    @SaIgnore
    public ResponseEntity<?> update(@RequestBody BusinessInputs temp){
        if(temp.getBusinessInputsIndex()==null){
            return ResponseEntity.ok(businessInputsServiceImpl.add(temp));
        }
        return ResponseEntity.ok(businessInputsServiceImpl.update(temp));
    }

    /**
     * 删除（业务输入信息）
     * @param businessInputsIndex 业务输入ID
     */
    @Operation(summary = "删除（业务输入信息）", description = "删除（业务输入信息）")
    @GetMapping("delete")
    @SaIgnore
    public ResponseEntity<?> delete(@Parameter Integer businessInputsIndex){
        if(CommonUtils.varIsBlank(businessInputsIndex)){
            return ResponseEntity.ok(0);
        }

        return ResponseEntity.ok(businessInputsServiceImpl.delete(Collections.singleton(businessInputsIndex)));
    }

}
